package edu.scu.declaresys.web.util;

import org.displaytag.decorator.TableDecorator;

import edu.scu.declaresys.config.IActionName;
import edu.scu.declaresys.vo.News;
import edu.scu.declaresys.vo.Project;
import edu.scu.declaresys.vo.User;

public class DisplaytagWrapper extends TableDecorator
{
	public static final String DECLARE_COMMITED = "declareCommitted";
	
	public static final String RCMD_WAIT_RCMD = "rcmdWaitRcmd";

	public static final String AUDIT_WAIT_AUDIT_OPERATION = "auditWaitAuditOperation";
	
	public static final String AUDIT_MODIFY_REQUEST_OPERATION = "auditModifyRequestOperation";
	
	public static final String PROJECT_NAME = "projectName";
	
	public static final String VIEW_PROJECT = "viewProject";
	
	public static final String NEWS_TITLE = "newsTitle";
	
	public static final String NEWS_OPERATION = "newsOperation";
	
	public static final String USER_LIST_OPERATION = "userListOperation";
	
	public String getUserListOperation()
	{
		User  obj=(User) this.getCurrentRowObject();
		return "<a href=\"" + IActionName.USER_DELETE + "?id=" + obj.getId() + "\">删除</a>";	
	}
	
	public String getNewsTitle()
	{
		News  obj=(News) this.getCurrentRowObject();
		return "<a href=\"" + IActionName.NEWS_DETAIL + "?id=" + obj.getId() + "\">" +  obj.getTitle() + "</a>";	
	}
	
	public String getNewsOperation()
	{
		News  obj=(News) this.getCurrentRowObject();
		int id = obj.getId();
		StringBuffer sb = new StringBuffer();
		sb.append("<a href=\"").append(IActionName.NEWS_DETAIL).append("?").append(Project.T_ID).append("=").append(id).append("\">查看</a>");
		sb.append("<a href=\"").append(IActionName.NEWS_DELETE).append("?").append(Project.T_ID).append("=").append(id).append("\">&nbsp;|&nbsp删除</a>");
		return sb.toString();
	}
	
	
	public String getDeclareCommitted()
	{
		Project  obj=(Project) this.getCurrentRowObject();
		
		//
		// 查看、修改、请求修改
		//
		StringBuffer sb = new StringBuffer();
		int state = obj.getState();
		
		boolean canModify = !(state == Project.STATE_PASSED || state == Project.STATE_REJECTED);

		int id=obj.getId();
		sb.append("<a href=\"").append(IActionName.GENERAL_VIEW_PROJECT).append("?").append(Project.T_ID).append("=").append(id).append("\">查看</a>");
		if(canModify)
		{
			if(state == Project.STATE_UNAUDIT_UNMODIFIABLE)
			{
				sb.append("<a href=\"").
				append(IActionName.DECLARE_REQUEST_MODIFY_MY_PROJECT).append("?").append(Project.T_ID).append("=").append(id)
				.append("\">&nbsp;|&nbsp请求修改</a>");
			}
			else if(state != Project.STATE_REQUEST_MODIFY)
			{
				sb.append("<a href=\"").
				append(IActionName.GENERAL_SHOW_PROJECT_FOR_MODIFY).append("?").append(Project.T_ID).append("=").append(id)
				.append("\">&nbsp;|&nbsp修改</a>");
			}
		}
		return sb.toString();
	}

	public String getRcmdWaitRcmd()
	{
		Project  obj=(Project) this.getCurrentRowObject();
		int id = obj.getId();
		StringBuffer sb = new StringBuffer();
		sb.append("<a href=\"").append(IActionName.RCMD_PROJECT).append("?").append(Project.T_ID).append("=").append(id).append("\">推荐</a>");
		sb.append("<a href=\"").append(IActionName.RCMD_DISRCMD_PROJECT).append("?").append(Project.T_ID).append("=").append(id).append("\">&nbsp;|&nbsp退回</a>");
		return sb.toString();
	}

	public String getAuditWaitAuditOperation()
	{
		Project  obj=(Project) this.getCurrentRowObject();
		int id = obj.getId();
		StringBuffer sb = new StringBuffer();
		sb.append("<a href=\"").append(IActionName.AUDIT_PASS).append("?").append(Project.T_ID).append("=").append(id).append("\">通过</a>");
		sb.append("<a href=\"").append(IActionName.AUDIT_REJECT).append("?").append(Project.T_ID).append("=").append(id).append("\">&nbsp;|&nbsp退回</a>");
		return sb.toString();
	}
	
	public String getAuditModifyRequestOperation()
	{
		Project  obj=(Project) this.getCurrentRowObject();
		int id = obj.getId();
		StringBuffer sb = new StringBuffer();
		sb.append("<a href=\"").append(IActionName.AUDIT_MODIFY_REQUEST_CONFIRM).append("?").append(Project.T_ID).append("=").append(id).append("\">同意</a>");
		sb.append("<a href=\"").append(IActionName.AUDIT_MODIFY_REQUEST_REJECT).append("?").append(Project.T_ID).append("=").append(id).append("\">&nbsp;|&nbsp不同意</a>");
		return sb.toString();
	}
	
	public String getProjectName()
	{
		Project obj = (Project)this.getCurrentRowObject();
		return "<a href=\"" + IActionName.GENERAL_VIEW_PROJECT + "?id=" + obj.getId() + "\">" + obj.getName() + "</a>";	
	}

	public String getViewProject()
	{
		Project obj = (Project)this.getCurrentRowObject();
		return "<a href=\"" + IActionName.GENERAL_VIEW_PROJECT + "?id=" + obj.getId() + "\">查看</a>";	
	}
}
